package wnhz.com.business.groupshop.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import wnhz.com.business.R;
import wnhz.com.business.base.BaseRecyclerAdapter;
import wnhz.com.business.base.RecyclerViewHolder;
import wnhz.com.business.groupshop.bean.GoodsBean;
import wnhz.com.business.groupshop.bean.HomeIndexBean;
import wnhz.com.business.impl.ITaskFinishListener;

/**
 * Created by Administrator on 2017/6/28 0028.
 */

public class MainGoodsAdapter extends BaseRecyclerAdapter<HomeIndexBean.InfoBean.GoodsBean> {
    static final String TAG = "MainGoodsAdapter";

    public MainGoodsAdapter(Context context, List<HomeIndexBean.InfoBean.GoodsBean> datas) {
        super(context, datas, R.layout.item_goods);
    }

    @Override
    protected void bindViewHolder(int position, RecyclerViewHolder holder) {
        ImageView img = holder.getView(R.id.iv_img, false);
        TextView title = holder.getView(R.id.tv_title, false);
        TextView money = holder.getView(R.id.tv_money, false);
        TextView tv_collectNum = holder.getView(R.id.tv_collectNum,false);
        LinearLayout ll_boss = holder.getView(R.id.ll_boss,false);

        title.setText(datas.get(position).getGoods_name());
        money.setText("¥"+datas.get(position).getGroup_price());
        tv_collectNum.setText(datas.get(position).getSales());
        Glide.with(context).load(datas.get(position).getLogo_pic()).into(img);
    }

    @Override
    protected void loadData(int page, final ITaskFinishListener iTaskFinishListener) {
//        SharedPreferences sp = context.getSharedPreferences("user", Context.MODE_PRIVATE);
//        String token = sp.getString("token", "");
//        Map<String, Object> map = new HashMap<>();
//        map.put("token", token);
//
//        XUtil.Post(Url.INDEX_INDEX, map, new MyCallBack<String>() {
//            @Override
//            public void onSuccess(String result) {
//                super.onSuccess(result);
//                LogUtils.e("======loadData = 首页列表数据==== ", result);
//                try {
//                    JSONObject jsonObject = new JSONObject(result);
//                    String re = jsonObject.optString("re");
//                    if ("1".equals(re)) {
////                        Gson gson = new Gson();
////                        HomeBean homeBean = gson.fromJson(result, HomeBean.class);
////
////                        iTaskFinishListener.onSuccess(TAG, homeBean.getGoood());
//                    }
//
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public void onFinished() {
//                super.onFinished();
//            }
//
//        });

//        List<GoodsBean> data = new ArrayList<>();
//        for(int i = 0; i < 9; i++){
//            GoodsBean goodsBean = new GoodsBean();
//            goodsBean.setCollect_status("" + i);
//            data.add(goodsBean);
//        }
//        iTaskFinishListener.onSuccess(TAG, data);
    }

    @Override
    protected void setPageSize(int pageSize) {

    }
}
